<template>
  <!--  我的 抖音详情 音乐 -->
  <div id="matemusic">
    <section class="input_group">
      <input type="text"
             v-model="input01"
             placeholder="请输入关键词找热门视频"
             @keyup.enter="search_input()"
             onfocus="if(this.value=='请输入关键词找热门视频'){this.value=''};this.style.color='#333';">
      <div @click="search_input()"
           class="search">
        <img src="@/assets/two/seach.png">
      </div>
    </section>
    <!-- 主体内容 -->
    <van-loading size="24px"
                 v-if="loading_01"
                 vertical>拼命加载中...</van-loading>
    <van-pull-refresh v-model="refreshing"
                      @refresh="onRefresh">
      <div class="box"
           v-for="(item, index) in musicList"
           :key="'music'+ index"
           @click="seeDetails(item.music_id, item)">
        <div class="musleft">
          <p><a href="##"><img :src="item.thum_pic"></a></p>
          <p><img src="@/assets/two/musmus_03.jpg"></p>
        </div>
        <div class="musright">
          <p><img src="@/assets/two/mu02.jpg"
                 alt="">{{ item.title }}</p>
          <div class="boxx">
            <div class="leanl">
              <p>{{ fornum(item.duration) }}s</p>
              <p>时长</p>
            </div>
            <div class="leanr">
              <p>{{ format_num(item.user_count) }}</p>
              <p>使用人数</p>
            </div>
          </div>
        </div>
      </div>
    </van-pull-refresh>
    <p class="nothing"
       v-show="musicList.length!=0 && musicList.length==musicList.length">我是有底线的～</p>
    <div class="empty"
         v-show="!loading && musicList.length==0">
      <img src="@/assets/two/zanwushuju_03.jpg">
      <p>目前没有可以查看的数据哟，请稍后再试~</p>
    </div>

  </div>
</template>
<script>
export default {
  name: '',
  components: {},
  data() {
    return {
      page: 1,
      count: '',
      musicId: '',
      musicItem: {},
      musicList: [],
      input01: '',
      page01: 1,
      //触底
      loading: false,
      finished: false,
      refreshing: false,
      pageSize: 20,
      permissions: 1,
      loading_01: false,
    }
  },
  computed: {},
  watch: {},
  created() {},
  mounted() {
    this.GetmusicList()
  },
  methods: {
    search_input() {
      this.page01 = 1
      this.musicList = []
      this.GetmusicList()
    },
    GetmusicList() {
      let that = this
      this.loading = true
      this.loading_01 = true
      this.$axios
        .get('/api/music/find', {
          params: {
            title: that.input01,
            pageIndex: that.page,
            pageSize: 20,
          },
        })
        .then((res) => {
          if (res.data.code == 0) {
            this.musicList = this.musicList.concat(res.data.data)
            this.loading = false
            this.refreshing = false
            this.loading_01 = false
          }
          if (response.data.code == 1003) {
            this.permissions = 0
             this.loading = false
            this.loading_01 = false
          }
        })
        .catch((err) => {
          console.log(err)
        })
    },
    //    点击跳转到详情页
    seeDetails(musicId, item) {
      this.musicId = musicId
      this.musicItem = item
      this.musicDetails = true
    },

    //触底
    onLoad() {
      this.loading = true
      if (this.page * this.pageSize > this.musicList.length) {
        this.loading = false
        this.finished = true
      } else if (this.musicList.length > 0) {
        this.page = this.page + 1
        this.GetmusicList()
      }
    },
    onRefresh() {
      // 清空列表数据
      this.finished = false
      this.pageIndex = 1
      this.musicList = []
      // 重新加载数据
      // 将 loading 设置为 true，表示处于加载状态
      this.loading = false
      this.GetmusicList()
    },
  },
}
</script>
<style scoped lang="less">
#matemusic {
  background: #f1f1f1;
  min-height: 100vh;
  img {
    display: inline-block;
  }
  //   搜索栏
  .input_group {
    max-width: 9.2rem;
    position: absolute;
    top: -1.44rem;
    left: 0.4rem;
    input {
      width: 8.82rem;
      background: #f1f1f1;
      outline: none;
      border-radius: 0.4rem;
      border: 0;
      font-size: 0.346rem;
      font-family: PingFangSC-Regular;
      font-weight: normal;
      font-stretch: normal;
      line-height: 0.346rem;
      letter-spacing: 0px;
      color: #b5b5b5;
      padding: 0.266rem 0 0.266rem 0.4rem;
    }
    .search {
      position: absolute;
      top: 0.1rem;
      right: 0.42rem;
      width: 0.4rem;
      height: 0.4rem;
      img {
        width: 100%;
      }
    }
  }
  .box {
    width: 92%;
    margin: 0 auto;
    border: 1px solid transparent;
    border-radius: 8px;
    background: #fff;
    display: flex;
    margin-top: 0.186667rem;
    .musleft {
      width: 30%;
      padding: 7.2% 0 0 8%;
      position: relative;
      p:nth-of-type(1) {
        width: 2.133333rem;
        height: 2.133333rem;
        position: absolute;
        left: 0.266667rem;
        top: 0.266667rem;
        z-index: 10;
        img {
          border: solid 1px #e5e5e5;
        }
        a {
          display: block;
          width: 100%;
          height: 100%;
        }
      }
      p:nth-of-type(2) {
        width: 1.6rem;
        height: 1.6rem;
        position: absolute;
        right: 10.8%;
        top: 22%;
      }
      img {
        display: block;
        width: 100%;
        border-radius: 0.213rem;
      }
    }
    // 右侧
    .boxx {
      display: flex;
    }
    .musright {
      width: 68.9%;
      padding-top: 0.613333rem;
      > p {
        width: 5.466rem;
        font-size: 0.373333rem;
        line-height: 0.373333rem;
        color: #fd7f2c;
        padding-bottom: 0.426667rem;
        // 溢出显示三个点
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
      }
    }
    .musright > p > img {
      width: 0.4rem;
      margin-right: 10px;
    }
    .leanl {
      width: 3.013333rem;
      p {
        font-size: 0.266667rem;
        line-height: 0.266667rem;
      }
    }
    .musright .leanr p {
      font-size: 0.266667rem;
      line-height: 0.266667rem;
    }
    .musright .leanl p:nth-of-type(1),
    .musright .leanr p:nth-of-type(1) {
      padding-bottom: 0.133333rem;
      font-size: 0.266667rem;
      color: #222;
      font-family: Dinpro-medium;
    }
    .musright .leanl p:nth-of-type(2),
    .musright .leanr p:nth-of-type(2) {
      padding-bottom: 0.586667rem;
      color: #888;
    }
  }
  .empty {
    width: 100%;
    margin-top: 1.733333rem;
    text-align: center;
    font-size: 0.346667rem;
    color: #888;
    img {
      display: block;
      width: 9.2rem;
      margin: 0 auto;
    }
    p {
      line-height: 1rem;
    }
  }
  .nothing {
    width: 100%;
    line-height: 1rem;
    text-align: center;
    font-size: 0.346667rem;
    color: #888;
  }
}
</style>
